Fix containerized .NET project creation failing with exit code 73#4956
Fix containerized .NET project creation failing with exit code 73#4956
Conversation
When creating a containerized .NET project, `func init` runs first and creates files (.gitignore, .csproj, Program.cs, host.json, etc.). The subsequent `dotnet new func` command then fails with exit code 73 because those files already exist. Pass `--force` to `dotnet new` when creating containerized projects so it overwrites the files created by the preceding `func init` step. Fixes #4955 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes containerized C#/.NET project creation by ensuring the dotnet new template invocation can overwrite files created earlier by func init --docker, avoiding failures like exit code 73.
Changes:
- Extend
executeDotnetTemplateCreatewith an optional{ force?: boolean }and add--forcewhen enabled. - Enable
forcewhen creating containerized .NET projects inDotnetProjectCreateStep.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/templates/dotnet/executeDotnetTemplateCommand.ts | Adds support for optionally appending --force to dotnet new creation args. |
| src/commands/createNewProject/ProjectCreateStep/DotnetProjectCreateStep.ts | Passes { force: true } for containerized project creation to prevent file-exists failures. |
| } | ||
|
|
||
| await executeDotnetTemplateCreate(context, version, projTemplateKey, context.projectPath, identity, templateArgs); | ||
| await executeDotnetTemplateCreate(context, version, projTemplateKey, context.projectPath, identity, templateArgs, { force: !!context.containerizedProject }); |
There was a problem hiding this comment.
In the non-containerized path, confirmOverwriteExisting prompts the user about overwriting existing files, but the subsequent dotnet new invocation will still refuse to overwrite on collisions unless --force is passed. Since executeDotnetTemplateCreate now supports force, consider wiring the prompt result (or presence of conflicts) into this call so the UX matches the actual behavior (or otherwise clarify that the prompt is informational only).
- Use withFlagArg('--force', ...) instead of withArg('--force') as it
is purpose-built for boolean flags.
- Always pass force: true since the non-containerized path already
prompts the user via confirmOverwriteExisting before reaching
dotnet new, so --force is needed to match the confirmed intent.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Problem
When creating a containerized .NET project,
func initruns first and creates files (.gitignore,.csproj,Program.cs,host.json,local.settings.json,launchSettings.json). The subsequentdotnet new funccommand then fails with exit code 73 because those files already exist.Fix
Pass
--forceto thedotnet newcommand when creating containerized projects, so it overwrites the files created by the precedingfunc initstep.Changes
executeDotnetTemplateCommand.ts— Added optionaloptions?: { force?: boolean }parameter toexecuteDotnetTemplateCreate()and appends--forceto args when set.DotnetProjectCreateStep.ts— Passes{ force: true }whencontext.containerizedProjectis truthy.Fixes #4955